<!--suppress ALL -->
<include file="./Template/header.html" />

<link rel="stylesheet" type="text/css" href="/Template/css/finishedOrder.css?v=2020072201">
<script type="text/javascript" src="/Template/js/amazeui.js"></script>
<script type="text/javascript">


    $(function() {

        //初始化页面配置
        initPage("订单确认");

        var app = new Vue({
            el: '#container',
            data: {
            },
            methods: {
				createOrder: function() {
					var couponCode = "{$coupon.coupon_code}";
                    var productId = "{$product.product_id}";
                    var receiveName = $("input[name=receiveName]").val();
                    var receiveContact = $("input[name=receiveContact]").val();
                    var receiveAddress = $("input[name=receiveAddress]").val();
                    var patientName = $("input[name=patientName]").val();
//                    var doctorName = $("input[name=doctorName]").val();
//                    var hospitalName = $("input[name=hospitalName]").val();
                    var note = $("input[name=note]").val();
                    var needInvoice = $("select[name=needInvoice]").val();
                    var invoiceName = $("input[name=invoiceName]").val();
                    var invoiceNumber = $("input[name=invoiceNumber]").val();
//                    var invoiceDetail = $("input[name=invoiceDetail]").val();
                    var needPatient = $("input[name=needPatient]").val();

                    var data = {};

//                    if(number == 0) {
//                        alert("请选择规格");
//                        return false;
//                    }

                    if (isNullOrEmpty(patientName)) {
                        alert("请填写联系人");
                        return false;
                    }
//
//                    if ("{$coupon.need_doctor}" == "1"){
//                        if (isNullOrEmpty(doctorName)) {
//                            alert("请填写医生姓名");
//                            return false;
//                        }
//
//                        if (isNullOrEmpty(hospitalName)) {
//                            alert("请填写医院名称");
//                            return false;
//                        }
//					}

                    if(needInvoice != -1) {
                        if(needInvoice == 1) {
                            if (isNullOrEmpty(invoiceName)) {
                                alert("请填写发票抬头");
                                return false;
                            }
                            if (isNullOrEmpty(invoiceNumber)) {
                                alert("请填写纳税人识别号");
                                return false;
                            }
                        }
//                        if(isNullOrEmpty(receiveName)) {
//                            alert("请填写收件人姓名");
//                            return false;
//                        }
//                        if(isNullOrEmpty(receiveAddress)) {
//                            alert("请填写收件人地址");
//                            return false;
//                        }
                        if(isNullOrEmpty(receiveContact)) {
                            alert("请填写联系电话，用于接收电子发票");
                            return false;
                        }
                        if(!checkPhone(receiveContact)) {
                            alert("手机号位数不对");
                            return false;
                        }
                    }
//                    if(needInvoice != -1) {
//                        if(isNullOrEmpty(invoiceDetail)) {
//                            alert("请填写发票明细");
//                            return false;
//                        }
//                    }
                    data.couponCode = couponCode;
                    data.productId = productId;
                    data.receiveName = receiveName;
                    data.receiveContact = receiveContact;
                    data.receiveAddress = receiveAddress;
                    data.patientName = patientName;
//                    data.patientSex = patientSex;
//                    data.patientAge = patientAge;
//                    data.doctorName = doctorName;
//                    data.hospitalName = hospitalName;
                    data.note = note;
                    data.needInvoice = needInvoice;
                    data.invoiceName = invoiceName;
                    data.invoiceNumber = invoiceNumber;

                    if(confirm("请确认是否提交订单？")){
                        $.ajax({
                            url:"/wechat/order/createCouponOrder",
                            type:"post",
                            data:data,
                            dataType:"JSON",
                            beforeSend:function(){
                                $("#loadingToast").show();
                            },
                            complete:function(){
                                $('#loadingToast').hide();
                            },
                            success:function(data){
                                if(data.code != 200) {
                                    alert(data.msg);
                                    return false;
                                }
                                window.location.href = "/wechat/userCenter/payInfo/id/"+data.order_id;
                            },
                        })
                    }else{
                        return;
                    }


                }
            }
        })


        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("select[name=needInvoice]").change(function() {
            if($(this).val() == 1) {
                $(".item.invoice").show();
            } else {
                $(".item.invoice").hide();
            }
            if($(this).val() == -1) {
                $(".item.invoiceDetail").hide();
            } else {
                $(".item.invoiceDetail").show();
            }
            if($(this).val() == 2) {
                $(".item.invoiceName").show();
                $("input[name=invoiceName]").val($("input[name=patientName]").val());
            }
        });


        $("img.icon-up").click(function() {

            $(this).hide();
            $("img.icon-down").show();

            $(".size-detail").toggle();
            $(".size-comment").toggle();

        });

        $("img.icon-down").click(function() {

            $(this).hide();
            $("img.icon-up").show();

            $(".size-detail").toggle();
            $(".size-comment").toggle();
        });

    })

</script>

<div class="container" id="container">
	<!--input type="hidden" name="couponCode" value="{$coupon.coupon_code}" /-->
	<div class="product-detail">
		<img class="product-img" src="{$product.image_url}" alt="product">
		<div class="detail-info">
			<p class="product-price" style="color: #de7d74" id="productPrice">￥{$coupon.price}</p>
			<p class="product-name" style="font-weight: bold;">{$product.product_name}</p>
			<p class="product-size" style="color: #ed9a63">[ {$coupon.size} ] 码</p>
			<p class="number" style="float:left; width: 90%">
				<a style="color: #45a1de" v-if="'{$coupon.default_hospital_name}' != ''">医院：{$coupon.default_hospital_name}</a>
				&nbsp;&nbsp;
				<a style="color: #45a1de" v-if="'{$coupon.default_doctor_name}' != ''">医生：{$coupon.default_doctor_name}</a>
			</p>
			<p class="buy-time" style="font-size: 0.8rem">订购日期：{:date("Y-m-d")}</p>
		</div>
	</div>
	<div class="patient-info agent">
		<div class="item">
			<span>联系人</span>
			<input type="text" name="patientName" placeholder="请填写联系人">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<input type="hidden" name="needPatient">
	</div>
	<!--div class="doctor-info agent" v-if="'{$coupon.need_doctor}' == '1'">
        <div class="item">
            <span>医生</span>
            <input type="text" name="doctorName" value="{$coupon.default_doctor_name}" placeholder="">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item">
            <span>医院</span>
            <input type="text" name="hospitalName" value="{$coupon.default_hospital_name}" placeholder="">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
    </div-->

	<div class="product-need" style="margin-bottom: 0">
		<div class="item">
			<span>是否开发票</span>
			<input type="text" value="不开发票" name="needInvoice" readonly placeholder="">
			<select name="needInvoice" class="invoice-choose">
				<option value="-1">不开发票</option>
				<option value="1">公司发票</option>
				<option value="2">个人发票</option>
			</select>
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoice invoiceName" style="display: none;">
			<span>发票抬头</span>
			<input name="invoiceName" type="text" placeholder="请填写发票抬头">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoice" style="display: none;">
			<span>纳税人识别号</span>
			<input name="invoiceNumber" type="text" placeholder="请填纳税人识别号">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<!--div class="item invoiceDetail" style="display: none;">
			<span>发票明细</span>
			<input name="invoiceDetail" type="text" placeholder="请填写发票明细">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div-->
		<div class="item invoiceDetail1" style="display: none;">
			<span>收件人姓名</span>
			<input type="text" name="receiveName" placeholder="请填写收件人姓名">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoiceDetail" style="display: none;">
			<span>联系电话</span>
			<input type="text" name="receiveContact" placeholder="手机号用于接收电子发票">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoiceDetail1" style="display: none;">
			<span>收件地址</span>
			<input type="text" name="receiveAddress" placeholder="请填写收件地址">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<div class="address-info" style="margin-bottom: 1rem">

		<div class="item">
			<span>留言备注</span>
			<input type="text" name="note" placeholder="请编辑备注信息">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<div class="order-operation">
		<p style="margin-left: 20%;width: 40%">共<a style="color: #e97a15"> {$coupon.number} </a>件,合计：<span>￥{$coupon.price}</span> </p>
		<button id="submitBtn" class="submit-order" v-on:click="createOrder">提交订单</button>
	</div>
</div>
<include file="./Template/footer.html" />